# coding=utf-8
"""
    获取验证码
"""
from utils.do_sql import DoMySql


# @Time    :  2024-10-14 17:07:46
# @Author  :  jiangtong
# @Email   :  gingerqgyy@outlook.com
# @Project :  test_curl_convert
# @File    :  verify_code


def verify_code(venv):
    """
    获取验证码, 支持 beta / test / pre 三个环境
    数据库信息 :
        beta 环境 :
            库 : yl_message
            表 : sms_verify_code
        test 环境 :
            库 : yl_common
            表 : sms_verify_code
        pre 环境 :
            库 : yl_common_pre
            表 : sms_verify_code
    """
    do_sql_obj = DoMySql(venv=venv)

    # beta :
    if venv == 'beta':
        sql = 'select phone, verify_content as verify_code, DATE_FORMAT(create_time, "%Y-%m-%d %H:%i:%s") as create_time \
        from yl_message.sms_verify_code ORDER BY create_time desc limit 3;'
        return do_sql_obj.select_all(sql)

    # test / pre :
    database_postfix = '' if venv == 'test' else '_pre'
    sql = f'select phone, verify_content as verify_code, DATE_FORMAT(create_time, "%Y-%m-%d %H:%i:%s") as create_time \
    from yl_common{database_postfix}.sms_verify_code ORDER BY create_time desc limit 3;'
    return do_sql_obj.select_all(sql)


def verify_code_beta():
    """
    beta 环境的验证码数据库和 test/pre 不同
    beta 环境, 验证码库表 :
        库 : yl_message
        表 : sms_verify_code
        yl_message.sms_verify_code
    """
    do_sql_obj = DoMySql(venv='beta')
    sql = 'select phone, verify_content as verify_code, DATE_FORMAT(create_time, "%Y-%m-%d %H:%i:%s") as create_time \
    from yl_message.sms_verify_code ORDER BY create_time desc limit 3;'
    return do_sql_obj.select_all(sql)


if __name__ == '__main__':
    print(verify_code('test'))
    print(verify_code('pre'))
    print(verify_code('beta'))
